package com.ag.dgm.action;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.ag.bean.TbAdviceType;
import com.ag.common.BaseAction;
import com.ag.common.EventUtil;
import com.ag.common.IDUtil;
import com.ag.dgm.dao.TbAdviceWayDAO;
import com.ag.dgm.dao.TbEventDAOczy;
import com.ag.dgm.service.IAdviceTypeService;

@Controller("AdviceTypeAction")
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class AdviceTypeAction extends BaseAction {

	@Resource(name = "adviceTypeServiceImpl")
	private IAdviceTypeService service;
	private List<TbAdviceType> adviceTypes;
	private TbAdviceType tbAdviceType;
	private String result;
	private String textarea;
	
	@Resource(name="CZYtbEventczy")
	private TbEventDAOczy TEdao;

	public String getTextarea() {
		return textarea;
	}

	public void setTextarea(String textarea) {
		this.textarea = textarea;
	}

	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}

	public IAdviceTypeService getService() {
		return service;
	}

	public void setService(IAdviceTypeService service) {
		this.service = service;
	}

	public List<TbAdviceType> getAdviceTypes() {
		return adviceTypes;
	}

	public void setAdviceTypes(List<TbAdviceType> adviceTypes) {
		this.adviceTypes = adviceTypes;
	}

	public TbAdviceType getTbAdviceType() {
		return tbAdviceType;
	}

	public void setTbAdviceType(TbAdviceType tbAdviceType) {
		this.tbAdviceType = tbAdviceType;
	}

	public String find() {
		adviceTypes = service.findAll();
		return "main";
	}

	public String modify() {
		this.setResult("修改成功");
		try {
			service.modify(tbAdviceType);
		} catch (Exception e) {
			this.setResult("修改不成功");
		}
		return "modify_succ";
	}

	public String delete() {
		this.setResult("删除成功");

		try {
			service.delete(tbAdviceType);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "delete_succ";
	}

	public String add() {
		tbAdviceType.setA(IDUtil.PRESERVE);
		this.setResult("增加成功");
		try {
			service.add(tbAdviceType);
		} catch (Exception e) {
			this.setResult("增加不成功");
		}
		return "add_succ";
	}
	
	/*
	 *        czy  start   work/setPlanStandard.jsp
	 */
	
	/*
	 * 
	 * 得到当前tbEvent 从session中拿, 在baseAction中有了方法，
	 */
	public String findEventId() {
		String eidString = null;
		try {
			// eidString =
			// (String)com.ag.processing.ProcessingPlans.getCurrentEventId();
			System.out.println("这是findEventId_action方法");
			eidString = (String) this
					.getSessionAttribute(EventUtil.PROCESSING_EVENT_ID);
			System.out
					.println("这是findEventId_action方法,取得的eventId为" + eidString);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return eidString;
	}
	
	public String saveTextArea(){
		String eid=findEventId();
		TEdao.savePlanReason(eid,textarea);
		return "saveTextArea";
	}
	/*
	 *        czy  end
	 */

}
